#pragma once
#include <fstream>
#include <iostream>
#include <map>
#include <queue>


using namespace std;

namespace U33
{

	struct data
		{
			string word;
			int n;

			data()
			{
				word = "";
				n = 0;
			}
			

			friend bool operator< (const data& n1, const data& n2 ) {     return n1.n < n2.n;  } 

		};



        class MostFrecWord
        {
        private:
                map<string, int> ma;
				priority_queue<data> pq;
        public:

                MostFrecWord()
                {
                }

                ~MostFrecWord()
                {
                }

                void readFromFile()
                {
                        ifstream fin;
                        fin.open("nils_holgersson.txt");
                        string s;
                        while (fin.good())
                        {
                                fin >> s;
                                for (auto &m : ma)
                                {
                                        if (!m.first.compare(s))
                                        {
                                                m.second++;
                                        }
                                }
                                ma.insert(pair<string, int>(s, 1));
                        }
                }

                int MaxWord(string &ord)
                {
                        int max = 0;
                        string word;
                        for (auto &m : ma)
                        {
                                if (m.second > max)
                                {
                                        max = m.second;
                                        ord = m.first;
                                }
                        }
                        return max;
                }

				void add_to_queue()
				{
					data d1;
					for (auto &m : ma)
					{
						d1.word = m.first;
						d1.n = m.second;
						pq.push(d1);
					}
				
				}

				void Print_list()
				{
					string word;
					for(int i = 0 ; i < 20; i++)
					{
					
						cout << pq.top().word << "  was present " << pq.top().n << " times " << endl;
						pq.pop();
					
					}
				
				
				}

        };
}



